package com.laomuji.android.mvvm.demo.start

import android.content.Intent
import android.os.Bundle
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.laomuji.android.mvvm.base.BaseActivity
import com.laomuji.android.mvvm.base.BaseActivityViewModel
import com.laomuji.android.mvvm.databinding.ActivityStartPageBinding
import com.laomuji.android.mvvm.demo.firebase.FirebaseActivity
import com.laomuji.android.mvvm.utils.MyLog
import com.laomuji.android.mvvm.utils.google.GoogleAdId
import com.laomuji.android.mvvm.utils.google.GoogleInstallReferrer
import com.laomuji.android.mvvm.utils.language.LanguageCode
import com.laomuji.android.mvvm.utils.language.LanguageUtil
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

/**
 * 开始屏幕
 * api31新增
 * 如果没有设置开始屏幕就是白屏
 * 设置开始屏幕后打开app会把白屏替换为开始屏幕
 * @author laomuji666
 * @since 2024/2/21
 */
class StartPageActivity:BaseActivity<ActivityStartPageBinding,BaseActivityViewModel>() {
    override fun onCreate(savedInstanceState: Bundle?) {
        installSplashScreen()
        super.onCreate(savedInstanceState)
    }

    override fun initView() {
        LanguageUtil.initLanguage(this)
        LanguageUtil.setAppLanguage(LanguageCode.LAST)
        startActivity(Intent(this, FirebaseActivity::class.java))
        finish()
    }

    override fun initData() {
        GoogleInstallReferrer.initGoogleInstallReferrer(this, onGetReferrer = {
            MyLog.iCustom("tag_start_page","referrer:$it")
        })
        CoroutineScope(Dispatchers.Default).launch{
            val advertisingId = GoogleAdId(this@StartPageActivity).getAdvertisingId()
            MyLog.iCustom("tag_start_page","advertisingId:$advertisingId")
        }
    }
}